package ${package.Controller};

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.layuiframework.stereotype.util.ValidGroup;
import java.util.ArrayList;
import java.util.List;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import ${package.Vo}.${table.voName};
<#if entityLombokModel>
import lombok.Data;
</#if>
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if entityLombokModel>
@Data
</#if>
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Resource
    private ${table.serviceName} ${table.layuiServiceName};


    /**
     * 分页查询${table.comment}
     * @param vo        可选条件 <#if table.layuiNameColumn??>${table.layuiNameColumn.alias}(name)</#if>、 <#if table.layuiTimeColumn??>开始时间(startTime)、结束时间(endTime)、</#if>
     * @return          ${table.comment}分页信息
     */
    @PostMapping("/page${table.entityName}")
    public PageInfo<${table.entityName}> page${table.entityName}(@RequestBody ${table.voName} vo){
        return ${table.layuiServiceName}.page${table.entityName}(vo);
    }

    /**
     * 列表查询${table.comment}
     * @param vo        可选条件 <#if table.layuiNameColumn??>${table.layuiNameColumn.alias}(name)</#if>、 <#if table.layuiTimeColumn??>开始时间(startTime)、结束时间(endTime)、</#if>
     * @return          ${table.comment}列表信息
     */
    @PostMapping("/list${table.entityName}")
    public List<${table.entityName}> list${table.entityName}(@RequestBody ${table.voName} vo){
        return ${table.layuiServiceName}.list${table.entityName}(vo);
    }

    /**
     * 添加${table.comment}基础信息
     * @param ${table.layuiEntityName}       ${table.comment}信息
     * @return          成功or失败
     */
    @PostMapping("/add${table.entityName}")
    public boolean add${table.entityName}(@RequestBody @Validated({ValidGroup.Insert.class}) ${table.entityName} ${table.layuiEntityName}, HttpServletRequest request){
        return ${table.layuiServiceName}.add${table.entityName}(${table.layuiEntityName}, request);
    }

    /**
     * 更新${table.comment}基础信息
     * @param ${table.layuiEntityName}       ${table.comment}信息, 主键信息必填
     * @return          成功or失败
     */
    @PostMapping("/update${table.entityName}")
    public boolean update${table.entityName}(@RequestBody @Validated({ValidGroup.Update.class}) ${table.entityName} ${table.layuiEntityName}){
        return ${table.layuiServiceName}.update${table.entityName}(${table.layuiEntityName});
    }

    /**
     * 删除${table.comment}基础信息
     * @param ${table.layuiEntityName}       ${table.comment}信息, 主键信息必填
     * @return          成功or失败
     */
    @PostMapping("/delete${table.entityName}")
    public boolean delete${table.entityName}(@RequestBody @Validated({ValidGroup.Delete.class}) ${table.entityName} ${table.layuiEntityName}){
        return ${table.layuiServiceName}.delete${table.entityName}(${table.layuiEntityName});
    }

    /**
     * ${table.comment}excel导入
     * @param file 前端传入的文件[一个or多个，这里导入只整一个]
     * @param request 请求对象
     * @return          成功or失败
     */
    @PostMapping("/excel${table.entityName}")
    public boolean excel${table.entityName}(@RequestPart(value = "file") MultipartFile file, HttpServletRequest request){
        return ${table.layuiServiceName}.excel${table.entityName}(file, new ArrayList<>(), request) == null;
    }

    /**
     * ${table.comment}excel导出
     * @param vo  页面传入参数(<#if table.layuiNameColumn??>name:${table.layuiNameColumn.alias};</#if><#if table.layuiTimeColumn??>startTime:开始时间;endTime:结束时间</#if> )
     * @param response 响应对象
     * @return   无返回值，通过响应对象响应信息
     * @throws Exception  调用方法可能发生io异常等
     */
    @GetMapping("/export${table.entityName}")
    public void export${table.entityName}(${table.voName} vo, HttpServletResponse response) throws Exception{
        ${table.layuiServiceName}.export${table.entityName}(vo, response);
    }
    <#if ES_URIS??>

     /**
     * 分页查询${table.comment} => 根据 lasticsearch 查询信息
     * @param vo        可选条件 <#if table.layuiNameColumn??>${table.layuiNameColumn.alias}(name)</#if>、 <#if table.layuiTimeColumn??>开始时间(startTime)、结束时间(endTime)、</#if>
     * @return          ${table.comment}分页信息
     */
     @PostMapping("/page${table.entityName}Es")
     public PageInfo<${table.entityName}> page${table.entityName}Es(@RequestBody ${table.voName} vo){
         return ${table.layuiServiceName}.page${table.entityName}Es(vo);
     }
    </#if>

 <#if !entityLombokModel>
  <#assign getprefix="get"/>
    public ${table.serviceName} ${getprefix}${table.serviceName}() {
        return ${table.layuiServiceName};
    }

  <#if chainModel>
    public ${table.controllerName} set${table.serviceName}(${table.serviceName} ${table.layuiServiceName}) {
  <#else>
    public void set${table.serviceName}(${table.serviceName} ${table.layuiServiceName}) {
  </#if>
        this.${table.layuiServiceName} = ${table.layuiServiceName};
  <#if chainModel>
        return this;
  </#if>
    }
 </#if>
}
</#if>
